Skip to content

AROSLSRE-1158: add --install-scope flag to hypershift install#8725

Open
shubhadapaithankar wants to merge 1 commit into
openshift:mainfrom
shubhadapaithankar:AROSLSRE-1158-add-install-scope-flag
Open

AROSLSRE-1158: add --install-scope flag to hypershift install#8725
shubhadapaithankar wants to merge 1 commit into
openshift:mainfrom
shubhadapaithankar:AROSLSRE-1158-add-install-scope-flag

Conversation

@shubhadapaithankar

@shubhadapaithankar shubhadapaithankar commented Jun 11, 2026

Copy link
Copy Markdown

What this PR does / why we need it

Adds a new --install-scope flag to the hypershift install command that controls which subset of manifests are applied:

  • all (default): installs CRDs and resources (existing behavior, fully backwards compatible)
  • crds: installs only CRDs
  • resources: installs only resources (operator deployment and RBAC)

Why we need it

In ARO-HCP, the HyperShift Helm chart uses post-install hooks to run hypershift install. There's a race condition where the operator starts and creates a ClusterSizingConfiguration before the Helm hook can apply its own version, causing apply conflicts.

Splitting the install into phases allows:

  1. CRDs to be installed first (--install-scope=crds)
  2. CRD-dependent manifests (like ClusterSizingConfiguration) to be applied by Helm
  3. The operator to start last (--install-scope=resources)

Which issue(s) this PR fixes

Fixes: https://redhat.atlassian.net/browse/AROSLSRE-1158
Related: https://redhat.atlassian.net/browse/AROSLSRE-313

Checklist

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

Summary by CodeRabbit

  • New Features

    • Added a new --install-scope option (default: all) to install CRDs only, resources only, or both.
    • Installer now applies and waits only for components relevant to the chosen scope.
  • Refactor

    • Improved output-format validation with clear predicates to select CRD vs resource output.
  • Tests

    • Added validation and rendering tests covering each outputs/scope mode and invalid values.

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jun 11, 2026
@openshift-ci-robot

openshift-ci-robot commented Jun 11, 2026

Copy link
Copy Markdown

@shubhadapaithankar: This pull request references AROSLSRE-1158 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "5.0.0" version, but no target version was set.

Details

In response to this:

What this PR does / why we need it

Adds a new --install-scope flag to the hypershift install command that controls which subset of manifests are applied:

  • all (default): installs CRDs and resources (existing behavior, fully backwards compatible)
  • crds: installs only CRDs
  • resources: installs only resources (operator deployment and RBAC)

Why we need it

In ARO-HCP, the HyperShift Helm chart uses post-install hooks to run hypershift install. There's a race condition where the operator starts and creates a ClusterSizingConfiguration before the Helm hook can apply its own version, causing apply conflicts.

Splitting the install into phases allows:

  1. CRDs to be installed first (--install-scope=crds)
  2. CRD-dependent manifests (like ClusterSizingConfiguration) to be applied by Helm
  3. The operator to start last (--install-scope=resources)

Which issue(s) this PR fixes

Fixes: https://redhat.atlassian.net/browse/AROSLSRE-1158
Related: https://redhat.atlassian.net/browse/AROSLSRE-313

Checklist

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

Made with Cursor

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci

openshift-ci Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Please specify an area label

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@openshift-ci openshift-ci Bot requested review from Nirshal and sdminonne June 11, 2026 21:23
@openshift-ci

openshift-ci Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: shubhadapaithankar
Once this PR has been reviewed and has the lgtm label, please assign muraee for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci Bot added the area/cli Indicates the PR includes changes for CLI label Jun 11, 2026
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: fa6a1436-aed9-4862-b8f2-5311621185a2

📥 Commits

Reviewing files that changed from the base of the PR and between 90f713b and 67b79f6.

📒 Files selected for processing (3)
  • cmd/install/install.go
  • cmd/install/install_render.go
  • cmd/install/install_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/install/install.go

📝 Walkthrough

Walkthrough

This PR adds an InstallScope string to Options, validates it to allow only "", "all", "crds", or "resources", wires a new --install-scope CLI flag defaulting to "all", and changes InstallHyperShiftOperator to conditionally perform CRD dry-run/coordination/application and wait logic only when scope includes CRDs, and to apply operator resources and wait for deployment availability only when scope includes resources. It also adds Outputs.IsValid(), IncludesCRDs(), and IncludesResources(), removes the sets import, and updates ValidateRender to use Outputs.IsValid().

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant InstallHyperShiftOperator
  participant ClusterCAPI
  participant KubernetesAPI
  participant Deployment

  CLI->>InstallHyperShiftOperator: call with InstallScope
  alt InstallScope == "all" or "crds"
    InstallHyperShiftOperator->>KubernetesAPI: perform CRD dry-run validation
    InstallHyperShiftOperator->>ClusterCAPI: detect/coordinate Cluster CAPI (unmanaged CRDs)
    InstallHyperShiftOperator->>KubernetesAPI: apply CRDs
    InstallHyperShiftOperator->>KubernetesAPI: waitUntilEstablished
  end
  alt InstallScope == "all" or "resources"
    InstallHyperShiftOperator->>KubernetesAPI: apply operator resources
    InstallHyperShiftOperator->>Deployment: WaitUntilAvailable
  end
Loading
🚥 Pre-merge checks | ✅ 10 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Test Structure And Quality ⚠️ Warning In cmd/install/install_test.go there are assertions without failure messages: g.Expect(err).NotTo(HaveOccurred()) at lines ~1845 and ~2157, violating the assertion-message requirement. Add a descriptive message to the two g.Expect(err).NotTo(HaveOccurred()) calls (e.g., “failed to setup CA” / “failed to render operator manifests”) or refactor to use g.Expect(err).ToNot(HaveOccurred(), …).
✅ Passed checks (10 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: adding an --install-scope flag to the hypershift install command.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed In cmd/install/install_test.go, all t.Run subtest titles are fixed strings (e.g., “When webhooks are enabled…”) with no dates, UUIDs, IPs, or generated pod/namespace suffixes detected.
Topology-Aware Scheduling Compatibility ✅ Passed PR #8725 patch diff adds --install-scope and render/output filtering; searching the diff for affinity/anti-affinity topologySpreadConstraints PDB nodeSelector/control-plane and maxUnavailable:0 fou...
Ipv6 And Disconnected Network Test Compatibility ✅ Passed git diff origin/main..FETCH_HEAD changes only cmd/install/* and kubeconfig unit tests; no test/e2e Ginkgo specs added, so no IPv4/disconnected-network assumptions to flag.
No-Weak-Crypto ✅ Passed Checked PR’s install.go/install_render.go/install_test.go at commit ed5f298 for md5/sha1/DES/RC4/3DES/Blowfish/ECB and crypto/ imports; none found, and no subtle.ConstantTimeCompare/bytes.Equal occ...
Container-Privileges ✅ Passed cmd/install assets/operator deployment sets securityContext {Privileged:false, AllowPrivilegeEscalation:false, RunAsUser:1000} and cmd/install{,.render,.test}.go contain no hostPID/hostNetwork/host...
No-Sensitive-Data-In-Logs ✅ Passed Scanned cmd/install/install.go/install_render.go/install_test.go for log/printf calls containing sensitive terms (password/token/api key/secret/etc); only progress/validation errors found, no secre...

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@shubhadapaithankar shubhadapaithankar force-pushed the AROSLSRE-1158-add-install-scope-flag branch from fe80425 to ed5f298 Compare June 11, 2026 21:26
@shubhadapaithankar

Copy link
Copy Markdown
Author

/area hypershift-operator

@openshift-ci openshift-ci Bot added the area/hypershift-operator Indicates the PR includes changes for the hypershift operator and API - outside an OCP release label Jun 11, 2026
@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 40 lines in your changes missing coverage. Please review.
✅ Project coverage is 41.67%. Comparing base (d574e2f) to head (67b79f6).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
cmd/install/install.go 9.52% 38 Missing ⚠️
cmd/install/install_render.go 88.88% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8725      +/-   ##
==========================================
+ Coverage   41.59%   41.67%   +0.08%     
==========================================
  Files         758      758              
  Lines       93925    93949      +24     
==========================================
+ Hits        39066    39152      +86     
+ Misses      52113    52049      -64     
- Partials     2746     2748       +2     
Files with missing lines Coverage Δ
cmd/install/install_render.go 60.24% <88.88%> (+3.22%) ⬆️
cmd/install/install.go 62.83% <9.52%> (-0.24%) ⬇️

... and 1 file with indirect coverage changes

Flag Coverage Δ
cmd-support 34.99% <33.33%> (+0.03%) ⬆️
cpo-hostedcontrolplane 44.00% <ø> (+0.40%) ⬆️
cpo-other 43.45% <ø> (ø)
hypershift-operator 51.65% <ø> (ø)
other 31.56% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@shubhadapaithankar shubhadapaithankar force-pushed the AROSLSRE-1158-add-install-scope-flag branch from ed5f298 to ff45f66 Compare June 11, 2026 21:52

@celebdor celebdor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! The approach makes sense given the container constraints (no kubectl available in the Helm hook image).

The hypershift install render subcommand already defines an Outputs type with OutputAll, OutputCRDs, and OutputResources constants, along with validation logic in ValidateRender(). This PR duplicates those values as raw strings in both the validation switch and the scope conditionals.

I'd suggest reusing the existing type by adding methods to it:

func (o Outputs) IsValid() bool {
    switch o {
    case OutputAll, OutputCRDs, OutputResources:
        return true
    default:
        return false
    }
}

func (o Outputs) IncludesCRDs() bool {
    return o == OutputAll || o == OutputCRDs
}

func (o Outputs) IncludesResources() bool {
    return o == OutputAll || o == OutputResources
}

Then the install path becomes:

scope := Outputs(opts.InstallScope)
if scope == "" {
    scope = OutputAll
}

if scope.IncludesCRDs() {
    // ...
}
if scope.IncludesResources() {
    // ...
}

And the validation simplifies to:

if o.InstallScope != "" && !Outputs(o.InstallScope).IsValid() {
    errs = append(errs, fmt.Errorf("invalid --install-scope value %q: must be '%s', '%s', or '%s'", o.InstallScope, OutputAll, OutputCRDs, OutputResources))
}

This also benefits the render path — its switch and validation can use the same methods, and the sets import can be dropped.

Additionally, the --outputs scope filtering on the render side has no test coverage today either. Since both paths would now share the same methods, adding a test that calls RenderHyperShiftOperator with each scope value and asserts CRDs vs resources in the output (using *apiextensionsv1.CustomResourceDefinition type checks) would cover the logic for both commands. I prototyped this locally — happy to share the test if helpful.

@celebdor

Copy link
Copy Markdown
Collaborator

I prototyped the aforementioned refactor and tests at celebdor/hypershift@prototype/install-scope-dry. Feel free to disregard, cherry-pick or adapt as you see fit.

@shubhadapaithankar shubhadapaithankar force-pushed the AROSLSRE-1158-add-install-scope-flag branch from ff45f66 to 90f713b Compare June 11, 2026 22:21
Add a new --install-scope flag to the hypershift install command that
controls which subset of manifests are applied:

- "all" (default): installs CRDs and resources (existing behavior)
- "crds": installs only CRDs
- "resources": installs only resources (operator deployment and RBAC)

Reuses the existing Outputs type from the render subcommand, adding
IsValid(), IncludesCRDs(), and IncludesResources() helper methods.
Both the install and render paths now use the shared methods, and the
render path's switch statement is replaced with the same conditional
pattern. The sets import is dropped.

Includes unit tests for validation (valid/invalid scope values) and
render output filtering (verifying CRDs vs resources in output).

This enables consumers to split the hypershift install into phases,
allowing CRD-dependent manifests to be applied between the CRD
installation and operator startup.

Ref: https://redhat.atlassian.net/browse/AROSLSRE-1158

Co-authored-by: celebdor <[email protected]>
Co-authored-by: Cursor <[email protected]>
@shubhadapaithankar shubhadapaithankar force-pushed the AROSLSRE-1158-add-install-scope-flag branch from 90f713b to 67b79f6 Compare June 11, 2026 22:34
@shubhadapaithankar

Copy link
Copy Markdown
Author

Thanks @celebdor for the review and the prototype! Addressed all feedback:

  • Refactored to reuse the existing \Outputs\ type from \install_render.go\ with \IsValid(), \IncludesCRDs(), \IncludesResources()\ helper methods
  • Both \install.go\ and \install_render.go\ now use the shared helpers (dropped \sets\ import from render path)
  • Added unit tests: 4 validation cases in \TestOptions_Validate\ for --install-scope\ + \TestRenderOutputsScope\ integration test that verifies CRD vs resource filtering via \RenderHyperShiftOperator\
  • All CI passing, Codecov green

@openshift-ci

openshift-ci Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

@shubhadapaithankar: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@hypershift-jira-solve-ci

hypershift-jira-solve-ci Bot commented Jun 11, 2026

Copy link
Copy Markdown

Confirmed. Now I have all the evidence needed.

Test Failure Analysis Complete

Job Information

Test Failure Analysis

Error

33.33% of diff hit (target 41.59%)

Summary

The codecov/patch check failed because only 33.33% of the new/changed executable lines introduced by this PR are covered by tests, falling short of the 41.59% minimum patch coverage threshold. The coverage gap is caused entirely by the new scope-based conditional logic added inside InstallHyperShiftOperator() in cmd/install/install.go, which connects to a real Kubernetes cluster (util.GetClient(), apply(), dryRunValidateCRDs(), etc.) and is therefore never called from any unit test. All changes in cmd/install/install_render.go (the IsValid(), IncludesCRDs(), IncludesResources() methods and the RenderHyperShiftOperator/ValidateRender refactors) are fully covered by TestRenderOutputsScope and TestOptions_Validate.

Root Cause

The PR adds ~32 new executable lines inside InstallHyperShiftOperator() in cmd/install/install.go that restructure the CRD-apply and resource-apply logic into scope.IncludesCRDs() / scope.IncludesResources() conditional blocks. None of these lines are covered because:

  1. InstallHyperShiftOperator() is never called from any test — confirmed by grepping install_test.go, which contains zero references to this function.
  2. The function is inherently untestable as a unit — it immediately calls util.GetClient() to obtain a real Kubernetes client, then performs live cluster operations (dryRunValidateCRDs, apply, waitUntilEstablished, WaitUntilAvailable, isClusterAPIRegistered, etc.).
  3. The flag registration line (cmd.PersistentFlags().StringVar(&opts.InstallScope, ...)) in NewCommand() is also uncovered since NewCommand() is not called in tests.

The ~15 covered lines come from install_render.go (the three new Outputs methods + the refactored render/validate logic) and the 2 validation lines in Validate(), which are well-exercised by TestRenderOutputsScope and the new TestOptions_Validate cases. But these ~17 covered lines out of ~49 total new executable lines yields only ~33-35% coverage, below the 41.59% target.

Recommendations
  1. Extract the scope-filtering logic into a testable helper function. Move the "which manifests to install" decision out of InstallHyperShiftOperator() into a pure function like:

    func filterManifestsByScope(crds, objects []crclient.Object, scope Outputs) (crdsToDeploy, objectsToDeploy []crclient.Object) {
        if scope.IncludesCRDs() { crdsToDeploy = crds }
        if scope.IncludesResources() { objectsToDeploy = objects }
        return
    }

    This function can be unit tested trivially without a Kubernetes cluster, covering the branching logic that is currently uncovered.

  2. Alternatively, increase coverage on the render side. Add test cases that exercise the error/default branches — e.g., test IsValid() with an empty string, test IncludesCRDs()/IncludesResources() with an invalid value — to push the covered line count up enough to cross the 41.59% threshold (need roughly 4-5 more covered lines).

  3. Consider whether the codecov target is achievable for this kind of change. If the project policy is to maintain >41.59% patch coverage and the bulk of the change is in a function that requires a live cluster, the code needs to be restructured to separate pure logic from cluster-side-effecting code.

Evidence
Evidence Detail
Reported coverage 33.33% of diff hit (target 41.59%)
Coverage gap ~8.26 percentage points below target
Uncovered file cmd/install/install.goInstallHyperShiftOperator() function
Uncovered lines (~32) Scope assignment (scope := Outputs(opts.InstallScope)), scope.IncludesCRDs() block (CRD validation, ClusterAPI coordination, apply CRDs, wait logic), scope.IncludesResources() block (apply objects, wait logic), flag registration in NewCommand()
Covered file cmd/install/install_render.go — all new/changed lines fully covered
Covered lines (~17) IsValid(), IncludesCRDs(), IncludesResources() methods, refactored ValidateRender() and RenderHyperShiftOperator(), validation in Validate()
Test calling InstallHyperShiftOperator None — function name absent from install_test.go
Test calling NewCommand None — function name absent from install_test.go
Why untestable InstallHyperShiftOperator() calls util.GetClient(), apply(), dryRunValidateCRDs() — all require a live Kubernetes cluster
Tests that DO provide coverage TestOptions_Validate (validation cases), TestRenderOutputsScope (render scope filtering)

@shubhadapaithankar

Copy link
Copy Markdown
Author

@Nirshal @sdminonne friendly ping - could you take a look when you get a chance? Small change adding --install-scope flag to split CRD vs resource installation. Tests included, celebdor's feedback addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cli Indicates the PR includes changes for CLI area/hypershift-operator Indicates the PR includes changes for the hypershift operator and API - outside an OCP release jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants